<template>
  <div class="table" id="table">
    <!-- 总览概况 -->
    <div class="analysis">
      <div class="analysis-box">
        <img class="analysis-img" src="../../assets/img/Home/12.png" alt />
        <div class="analysis-lable">传感器总数</div>
        <div class="analysis-num">{{ sensorCount }}</div>
      </div>
      <div class="analysis-box">
        <img class="analysis-img" src="../../assets/img/Home/13.png" alt />
        <div class="analysis-lable">今日报警数</div>
        <div class="analysis-num">{{ alarmCount }}</div>
      </div>
      <div class="analysis-box">
        <img class="analysis-img" src="../../assets/img/Home/14.png" alt />
        <div class="analysis-lable">今日已处理</div>
        <div class="analysis-num">{{ disposeCount }}</div>
      </div>
      <div class="analysis-box">
        <img class="analysis-img" src="../../assets/img/Home/15.png" alt />
        <div class="analysis-lable">今日故障数</div>
        <div class="analysis-num">{{ faultCount }}</div>
      </div>
    </div>

    <div class="but">
      <!-- 标题内容 -->
      <div class="title-container">
        <img class="img-bg" src="../../assets/img/Home/弹窗背景条.png" alt />
        <div class="title">实时预警台账</div>
      </div>

      <div class="search-container">
        <!-- 开始日期结束日期 -->
        <div class="title-search">
          <el-date-picker
            :clearable="needclearable"
            v-model="dateRange"
            type="datetimerange"
            size="small"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd hh:mm:ss"
            @change="dateHandler"
            popper-class="lcj-select-popup"
          ></el-date-picker>
        </div>
        <!-- 根据ID搜索 -->
        <div class="title-search">
          <el-input v-model="params.sorId" placeholder="请输入传感器ID"></el-input>
          <div class="title-search-word">
            <div class="title-but" @click="handleSearch">搜索</div>
            <div class="title-but" @click="resetParams">重置</div>
          </div>
        </div>
      </div>

      <div class="table-main">
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          :header-cell-style="{
            color: '#cccccc',
            background: '#1B3663',
            fontFamily: 'AlibabaPuHuiTi-2-55-Regular',
            fontSize: '16px',
            fontWeight: 'normal',
            lineHeight: '18px',
            letterSpacing: '0px',
            borderBottom: '1px solid rgba(255, 255, 255, 0.17)',
            height: '48px',
            padding: '7px 0',
          }"
          :row-style="{
            color: '#ffffff',
            background: '#08102a',
            opacity: '0.78',
            height: '48px',
            fontFamily: 'AlibabaPuHuiTi-2-85-Regular',
            fontSize: '16px',
            fontWeight: 'normal',
            lineHeight: '18px',
            letterSpacing: '0px',
          }"
          :cell-style="{
            padding: '6px 0',
            border: 'none',
            borderBottom: '1px solid rgba(255, 255, 255, 0.17)',
          }"
        >
          <!-- 表格内容 -->
          <el-table-column prop="sorId" align="center" label="传感器ID"></el-table-column>
          <el-table-column prop="address" align="center" label="所属火区"></el-table-column>
          <el-table-column prop="lonAndLat" align="center" label="经纬度"></el-table-column>
          <el-table-column prop="qaType" align="center" label="问题类型">
            <template slot-scope="scope">
              <span class="qaStyle">{{ scope.row.qaType }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="sensortemp" align="center" label="实时温度"></el-table-column>
          <el-table-column prop="sensorvoltage" align="center" label="实时电压"></el-table-column>
          <el-table-column prop="currenttime" align="center" label="最新更新时间"></el-table-column>
          <el-table-column label="功能" align="center">
            <template slot-scope="scope">
              <div class="function">
                <img
                  @click="flyMap(scope.row)"
                  class="flyIco"
                  src="../../assets/img/Home/飞览.png"
                  alt
                />
                <a class="checkDetail" @click="detailCheck(scope.row)">查看详情</a>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页功能 -->
      <div class="page" v-if="this.tableData.length">
        <el-pagination
          small
          layout="total, prev,pager,next"
          :total="total"
          :page-size="params.pageSize"
          :pager-count="5"
          :current-page.sync="params.pageNum"
          @current-change="getPageData"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { sensorUIList, analysisData } from "@/api/data/home";
import { formatDate } from "@/utils/index";

export default {
  name: "homeTable",
  components: {},
  data() {
    return {
      needclearable: false,
      tableData: [],
      allList: [],
      // 日期范围
      dateRange: [],
      params: {
        sorId: "",
        address: "",
        pageNum: 1,
        pageSize: 5,
        startTime: "",
        endTime: ""
      },
      total: 0,
      //是否搜索
      searchActive: false,
      //传感器总数
      sensorCount: 0,
      //传感器总数
      alarmCount: 0, //今日报警数
      disposeCount: 0, //今日已处理
      faultCount: 0 //今日故障数
    };
  },
  // props: {
  //   show: {
  //     default: true,
  //   },
  // },
  computed: {},
  watch: {},
  created() {
    this.getTableData();
  },
  mounted() {},
  methods: {
    async getTableData() {
      const bp = await sensorUIList({
        ...this.params,
        sorId:
          Number(this.params.sorId) == 0 ? undefined : Number(this.params.sorId)
      });

      const analysis = await analysisData();
      if (analysis && analysis.data) {
        const {
          alarmCount,
          sensorCount,
          disposeCount,
          faultCount
        } = analysis.data;
        this.sensorCount = sensorCount;
        this.alarmCount = alarmCount;
        this.disposeCount = disposeCount;
        this.faultCount = faultCount;
      }
      if (bp.data && bp.data.rows) {
        this.allList = bp.data.rows.map(item => {
          const ojb = { ...item };
          if (item.longitude && item.latitude) {
            ojb.lonAndLat =
              item.longitude.toFixed(3) + "," + item.latitude.toFixed(3);
          }
          if (item.ifAlarm == 2) {
            ojb.qaType = "报警";
          }
          if (item.ifFault == 2) {
            ojb.qaType += " 故障";
          }
          return ojb;
        });
        this.total = bp.data.total;
        this.tableData = this.allList.slice(
          (this.params.pageNum - 1) * this.params.pageSize,
          this.params.pageNum * this.params.pageSize
        );
      } else {
        this.tableData = [];
      }
    },
    // 分页
    getPageData() {
      this.tableData = this.allList.slice(
        (this.params.pageNum - 1) * this.params.pageSize,
        this.params.pageNum * this.params.pageSize
      );
    },
    dateHandler() {
      if (this.dateRange && this.dateRange.length > 0) {
        this.params.startTime = this.dateRange[0];
        this.params.endTime = this.dateRange[1];
      } else {
        delete this.params.startTime;
        delete this.params.endTime;
      }
    },
    async Search() {
      this.params.pageNum = 1;
      this.getTableData();
    },
    async handleSearch() {
      this.params.pageNum = 1;
      this.getTableData();
    },
    async resetParams() {
      this.params.sorId = "";
      this.params.pageNum = 1;
      this.dateRange = [];
      this.params.startTime = "";
      this.params.endTime = "";
      this.getTableData();
    },
    // 详情查看
    detailCheck(row) {
      if (row.ifAlarm == 2 && row.ifFault != 2) {
        // this.$router.push("/alartSenor");
        this.$router.push({path: '/alartSenor',query:{SensorAlartData:row}});
      } else if (row.ifAlarm != 2 && row.ifFault == 2) {
        this.$router.push({path: '/problemSenor',query:{SensorAlartData:row}});
        // this.$router.push("/problemSenor");
      } else if (row.ifFault == 2 && row.ifAlarm == 2) {
        this.$router.push({path: '/problemSenor',query:{SensorAlartData:row}});
        // this.$router.push("/problemSenor");
      } else {
        this.$router.push("/houtai");
      }
    },
    // 飞地图
    flyMap(item) {
      this.$emit("handleClose", item);
    }
  },
  beforeDestroy() {
    // window.removeEventListener("pingan", this.LayerSearch);
  }
};
</script>

<style lang="scss" scoped>
.table {
  width: 100%;
  height: 638px;
  overflow: hidden;
  position: fixed;
  bottom: -18px;
  left: 0;
  z-index: 1000;
  background-image: url("../../assets/img/Home/弹窗背景.png");
  .analysis {
    display: flex;
    justify-content: space-around;
    height: 100px;
    .analysis-box {
      display: flex;
      justify-content: space-around;
      flex-direction: row;
      width: 452px;
      height: 100px;
      .analysis-img {
        position: absolute;
        top: 0;
        width: 452px;
        height: 100px;
      }
      .analysis-lable {
        font-family: "AlibabaPuHuiTi-2-105-Heavy";
        font-size: 24px;
        font-weight: normal;
        font-style: italic;
        font-stretch: normal;
        letter-spacing: 0px;
        color: #f6f9fe;
        position: relative;
        top: 0;
        left: -20px;
        height: 100px;
        line-height: 100px;
      }
      .analysis-num {
        font-family: "AlibabaPuHuiTi-2-105-Heavy";
        font-size: 48px;
        font-weight: normal;
        font-style: italic;
        font-stretch: normal;
        letter-spacing: 0px;
        color: #f6f9fe;
        // width: 100%;
        height: 100px;
        // box-shadow: 0px 2px 8px 0px rgba(5, 28, 55, 0.42);
        line-height: 100px;
        position: relative;
        top: 0;
        left: 10px;
      }
    }
  }
  .but {
    transition: bottom 0.5s linear;
    width: 100%;
    height: 538px;
    .title-container {
      width: 491px;
      height: 72px;
      margin-top: 20px;
      .img-bg {
        width: 491px;
        height: 41px;
        position: relative;
        left: 14px;
        top: 30px;
      }
      .title {
        width: 130px;
        height: 22px;
        font-family: "AlibabaPuHuiTi-2-105-Heavy";
        font-size: 22px;
        font-weight: normal;
        font-style: italic;
        font-stretch: normal;
        letter-spacing: 0px;
        color: #f6f9fe;
        box-shadow: 0px 2px 8px 0px rgba(5, 28, 55, 0.42);
        position: relative;
        left: 58px;
        top: -26px;
      }
    }
    .search-container {
      width: 98%;
      display: flex;
      justify-content: space-between;
      flex-direction: row;
      margin-top: 42px;
      .title {
        font-family: "AlibabaPuHuiTi-2-105-Heavy";
        font-size: 22px;
        font-weight: normal;
        font-style: italic;
        font-stretch: normal;
        letter-spacing: 0px;
        color: #f6f9fe;
        box-shadow: 0px 2px 8px 0px rgba(5, 28, 55, 0.42);
      }
    }
    .search-container {
      width: 98%;
      display: flex;
      justify-content: space-between;
      flex-direction: row;
      margin-top: 17px;
      .title-search {
        width: 300px;
        position: relative;
        color: #ffffff;
        font-family: "AlibabaPuHuiTi-2-85-Bold";
        margin-left: 50px;

        ::v-deep .el-input__inner {
          background-color: rgba(#2766ce, 0.3);
          border-radius: 21px;
          color: #fff;
          border: transparent;
        }
        .title-search-word {
          position: absolute;
          top: 7px;
          right: 10px;
          font-family: "AlibabaPuHuiTi-2-85-Bold";
          cursor: pointer;
          display: flex;
          .title-but {
            // background: #00ab9b;
            margin-right: 10px;
            padding-left: 5px;
            padding-right: 5px;
            border-radius: 5px;
            cursor: pointer;
          }
        }
      }
    }
    .table-main {
      width: 100%;
      height: calc(100% - 96px);
      // background-color: #001f1c;
      opacity: 0.8;
      padding: 20px;
      box-sizing: border-box;
      color: #ffffff;
      border-collapse: collspse;

      .qaStyle {
        font-family: "AlibabaPuHuiTi-2-55-Regular";
        font-size: 16px;
        font-weight: normal;
        font-stretch: normal;
        line-height: 18px;
        letter-spacing: 0px;
        color: #ff6363;
      }
      .function {
        display: flex;
        justify-content: center;
        .flyIco {
          cursor: pointer;
        }
        .checkDetail {
          margin-left: 20px;
          font-family: "AlibabaPuHuiTi-2-85-Regular";
          font-size: 16px;
          font-weight: normal;
          font-stretch: normal;
          letter-spacing: 0px;
          color: #f6f9fe;
        }
      }

      ::v-deep .el-table__row {
        height: 38px;
      }
      ::v-deep .el-table {
        background: transparent;
        padding-right: 0px;
      }
      ::v-deep .cell {
        padding-right: 0px;
      }
      ::v-deep .el-input__inner {
        background-color: rgba(#2766ce, 0.3);
        border-radius: 21px;
        color: #fff;
        border: transparent;
      }

      ::v-deep .el-table__body tr:hover > td {
        background-color: rgba(#2766ce, 0.3) !important;
      }

      .el-table--enable-row-hover .el-table__body tr:hover > td {
        background-color: rgba(#2766ce, 0.3) !important;
      }
    }
    .page {
      width: 16%;
      color: #ffffff;
      display: flex;
      align-items: center;
      // justify-content: flex-end;
      position: absolute;
      bottom: 37px;
      right: -8px;
      ::v-deep .el-icon-arrow-right {
        color: #ffffff;
      }

      ::v-deep .el-icon-arrow-left {
        color: #ffffff;
      }

      ::v-deep .el-pagination {
        color: #ffffff;
        font-family: "AlibabaPuHuiTi-2-55-Regular";
        font-size: 16px;
        font-weight: normal;
        font-stretch: normal;
        line-height: 18px;
        letter-spacing: 0px;
        .el-pager li {
          background: transparent;
          font-family: "AlibabaPuHuiTi-2-55-Regular";
          font-size: 16px;
          font-weight: normal;
          font-stretch: normal;
          line-height: 18px;
          letter-spacing: 0px;
        }
      }

      ::v-deep .el-pager li.btn-quicknext,
      ::v-deep .el-pager li.btn-quickprev,
      ::v-deep .el-pager li.btn-quicktatal {
        color: #ffffff;
      }

      ::v-deep .el-pagination__total {
        color: #ffffff;
        font-family: "AlibabaPuHuiTi-2-55-Regular";
        font-size: 16px;
        font-weight: normal;
        font-stretch: normal;
        line-height: 18px;
        letter-spacing: 0px;
      }
      ::v-deep .el-pager li.active {
        color: #25b390;
        font-family: "AlibabaPuHuiTi-2-55-Regular";
        font-size: 16px;
        font-weight: normal;
        font-stretch: normal;
        line-height: 18px;
        letter-spacing: 0px;
        font-weight: bold;
      }

      ::v-deep .el-pager li:hover {
        color: #25b390;
      }

      ::v-deep .el-pagination {
        .btn-next,
        .btn-prev {
          background: transparent;
        }
      }
    }
  }
}

::v-deep .el-table::before {
  background-color: transparent;
}
</style>

<style lang="scss">
.lcj-select-popup {
  background: #08102a !important;
  border: none !important;
  color: #fff !important;
  .el-picker-panel__footer {
    border: 1px solid rgba(255, 255, 255, 0.17) !important;
    background-color: #08102a;
  }
  .el-date-range-picker__time-header,
  .el-date-table th {
    border-bottom: 1px solid rgba(255, 255, 255, 0.17);
  }
  .el-date-range-picker__content.is-left {
    border-bottom: 0px solid rgba(255, 255, 255, 0.17);
  }
  .el-time-panel__content.has-seconds::before,
  .el-time-panel__content.has-seconds::after {
    border-bottom: 1px solid #5c5e63;
    border-top: 1px solid #5c5e63;
  }
  .el-time-panel__btn {
    border: none;
    line-height: 28px;
    padding: 0 5px;
    margin: 0 5px;
    cursor: pointer;
    font-family: "AlibabaPuHuiTi-2-105-Heavy";
    font-size: 14px;
    color: #009688;
  }
  .el-picker-panel__icon-btn {
    color: #fff;
  }
  .el-time-panel__btn.confirm,
  .el-time-spinner__item.active:not(.disabled) {
    font-weight: 800;
    color: #009688;
  }
  .el-time-spinner__item:hover:not(.disabled):not(.active) {
    background: transparent;
    color: #009688;
    cursor: pointer;
  }
  .el-date-range-picker__content.is-left {
    border-right: 1px solid rgba(255, 255, 255, 0.17);
  }
  .el-time-panel,
  .el-time-panel__footer {
    border-top: 1px solid rgba(255, 255, 255, 0.17);
    background-color: #08102a;
    border: 1px solid rgba(255, 255, 255, 0.17);
  }
  .popper__arrow {
    border-bottom-color: #439eff !important;
    &::after {
      border-bottom-color: #08102a !important;
    }
  }
  .el-input__inner,
  .el-input.is-disabled .el-input__inner {
    height: 36px;
    line-height: 36px;
    background: #1b3663;
    color: #fff;
    font-family: "AlibabaPuHuiTi-2-55-Regular";

    border: none;
  }
  .el-button.is-disabled.is-plain,
  .el-button.is-disabled.is-plain:hover,
  .el-button.is-disabled.is-plain:focus {
    background-color: transparent !important;
    border: none !important;
    color: #c0c4cc !important;
  }
  .el-button + .el-button,
  .el-button--text {
    background: transparent;
    border: none;
    span {
      font-family: "AlibabaPuHuiTi-2-105-Heavy";
      font-size: 16px;
      color: #25b390;
    }
  }
  .el-select-dropdown__item {
    color: #fff;
    &:hover {
      background: rgba(10, 152, 188, 0.3);
      color: #202d38;
    }
  }
  .el-select-dropdown__item.hover {
    background: rgba(10, 152, 188, 0.3);
    color: #202d38;
  }
  .el-scrollbar__wrap {
    overflow-x: hidden;
    margin-bottom: 0 !important;
  }
  .el-cascader-menu {
    border-right: solid 1px #439eff;
  }
  // .el-radio {
  //   display: none;
  // }
  .el-cascader-node.in-active-path,
  .el-cascader-node.is-selectable.in-checked-path,
  .el-cascader-node.is-active {
    color: rgba(10, 152, 188, 0.3);
    font-weight: bold;
  }
  .el-date-table td.in-range div,
  .el-date-table td.in-range div:hover,
  .el-date-table.is-week-mode .el-date-table__row.current div,
  .el-date-table.is-week-mode .el-date-table__row:hover div {
    background-color: transparent;
  }
  .el-date-table td.end-date span,
  .el-date-table td.start-date span {
    background-color: #08102a;
  }
  .el-cascader-node__label {
    color: #fff;
    z-index: 1;
    pointer-events: none;
  }
  .el-cascader-node:not(.is-disabled):hover,
  .el-cascader-node:not(.is-disabled):focus {
    background: #08102a;
  }
  .el-cascader-node__postfix {
    right: 30px;
    color: #08102a;
  }
  .el-radio__inner {
    border: 0;
    border-radius: 0;
    width: 170px;
    height: 34px;
    background-color: transparent;
    position: absolute;
    top: -18px;
    left: -19px;
  }

  .el-select-dropdown__item {
    color: #fff;
    &:hover {
      background: #08102a;
      color: #fff;
    }
    &:focus {
      background: #08102a;
      color: #fff;
    }
  }
  .el-select-dropdown__item.selected {
    color: #fff;
    background: #08102a;
  }
}
.el-date-editor {
  .el-range-input {
    background: transparent;
    font-family: "AlibabaPuHuiTi-2-55-Regular";
    font-size: 14px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 18px;
    letter-spacing: 0px;
    color: #cccccc;
  }
  .el-range__icon {
    color: #fff;
  }
  .el-range-separator {
    line-height: 27px !important;
    width: 7% !important;
    font-family: "AlibabaPuHuiTi-2-105-Heavy";
    font-size: 16px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 18px;
    letter-spacing: 0px;
    color: #ffffff;
  }
}
.el-date-table td.today span {
  color: #25b390;
  font-weight: 700;
  font-size: 16px;
  font-family: "AlibabaPuHuiTi-2-105-Heavy";
}
.el-date-table td.in-range div,
.el-date-table td.in-range div:hover {
  background-color: rgba(37, 179, 144, 0.3) !important;
}
.el-date-table td.in-range div,
.el-date-table td.in-range div:hover,
.el-date-table.is-week-mode .el-date-table__row.current div,
.el-date-table.is-week-mode .el-date-table__row:hover div {
  background-color: transparent;
}
.el-date-table td.end-date span,
.el-date-table td.start-date span {
  background-color: #25b390;
}
.el-popper[x-placement^="top"] .popper__arrow::after,
.el-popper[x-placement^="top"] .popper__arrow {
  border-top-color: transparent;
}
</style>
